-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support environent variables in config #1341
Conversation
52916c0
to
fb5fbc7
Compare
Hey! Thanks for tackling this. I think we wouldn't want to apply this as a pre-processing pass, otherwise it opens the door to pretty weird things if the environment variables contain things that could lead to valid YAML. What do you think of instead doing this replacement within |
Hmm, didn't see it. Will dig into it. |
easiest way is |
fb5fbc7
to
b391d41
Compare
b391d41
to
c8435b2
Compare
c8435b2
to
941a260
Compare
@arcanis I moved replacement into Not sure about tests: maybe we should separate it and check all cases in Also there is something strange with the test on win. |
Perfect! Thanks @7rulnik! 😃 |
Could we have some way to simply disable this functionality all together maybe via .yarnrc.yml or via an environment variable? |
Please open an issue with a repro. This PR is about the configuration, whereas you're talking about scripts 🙂 |
@yinzara Not sure what npmRegistries:
"//registry.npmjs.org":
"npmAuthToken": ${MY_AUTH_TOKEN} I believe you're referring to the environment variables inside our portable shell, which go through a completely different parser that correctly handles nested environment variables and a lot of other things. The portable shell has support for many features that work across all environments (including on Windows), like environment variables, command chains, subshells, some builtins. For your use case, you can:
Edit: @arcanis responded faster than me. 😄 |
THANKS! That's good enough! I appreciate it. |
I guess we can also add support for the Edit: I realize that the discussion shouldn't continue here, my bad. 🤦 |
I'll open another issue specifically to add $PWD resolution so it's bash compatible. I think that's an important thing. |
What's the problem this PR addresses?
Lack of support of environment variables in config files #1146
How did you fix it?
Stringify yarnrc configs, split it by variables, replace with value from
process.env
, and fallback if it's not set.I took fallback algorythm from docker-compose:
If you fine with this implementation I will add tests and will document this. Also I could rewrite it to deep-map and map strings only. It should be a better variant
Note that regexp named groups have limited support: http://kangax.github.io/compat-table/es2016plus/#test-RegExp_named_capture_groups. If this is a problem I can refactor it